<?php
include '../libraries/config.php';
include '../libraries/dbclass2.php';
include '../libraries/cache.php';

if(isset($_GET['all'])){
$db=new db;
$db->connect();
$db->query("select id,chap_id from chapterk_content where server='manga24h.com' and upload=0 order by id desc limit 0,500");
//$db->query("select id,chap_id from chapterk_content where server='blogspot' and upload=0 order by id desc limit 0,150");

$re=$db->fetchAll();
echo serialize($re);
$db->close();
}

if(isset($_GET['detail'])){
	$id=$_GET['id'];
	$db=new db;
	$db->connect();
	$db->query("select * from chapterk_content where  id=$id");
	$re=$db->fetchOne();
	echo serialize($re);
	$db->close();
}

if(isset($_GET['update'])){
	echo "Update ".$_GET['id']."<Br/>";
	$result=urldecode($_POST['content']);
	$id=$_GET['id'];
	$chap=$_GET['chap_id'];
	
	$result=unserialize($result);
	$picasa=unserialize($result['picasa']);
	$links=array();
	foreach($picasa as $link){
														$link=preg_replace('/https:\/\/lh3.googleusercontent.com/',"http://3.bp.blogspot.com",$link);
														$link=preg_replace('/https:\/\/lh4.googleusercontent.com/',"http://2.bp.blogspot.com",$link);
														$link=preg_replace('/https:\/\/lh5.googleusercontent.com/',"http://1.bp.blogspot.com",$link);
														$link=preg_replace('/https:\/\/lh6.googleusercontent.com/',"http://4.bp.blogspot.com",$link);
														$link = preg_replace('/\/s[0-9]*\//', '/s0/',$link);
														$links[]=$link;				
	}

	$result['picasa']=serialize($links);
	
	$db=new db;
	$db->connect();
	$db->nonquery("update  chapterk2 set check_link=0,check_error=0 where id=".intval($_GET['chap_id']));
		echo mysql_error();
	$db->nonquery("update  chapterk_content set upload=1,check_link=0,check_error=0 where chap_id=".intval($_GET['chap_id']));
		echo mysql_error();
	$db->nonquery("delete from chapterk3_content where chap_id=".intval($_GET['chap_id']));
		echo mysql_error();
	$db->nonquery("insert into chapterk3_content(id,chap_id,server,upload,error,page_error,picasa,email,abid) values(".$id.",".$chap.",'manga24h.com',1,".$result['error'].",".$result['page_error'].",'".$result['picasa']."','".$result['email']."','".$result['abid']."')");
	echo mysql_error();
	echo "Insert xong ".$_GET['chap_id']."\n";
	$db->close();
	
	
		$id=$_GET['chap_id'];
		$sub=$id%100;
		$cache=new cache;
		$cache->flush('manga_get_chapter_detail'.$id,'chapter/'.$sub);
	
}
?>